{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1ee0bcd1",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "各省各地的疫情具体情况\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>省份</th>\n",
       "      <th>城市</th>\n",
       "      <th>累计感染</th>\n",
       "      <th>死亡</th>\n",
       "      <th>治愈</th>\n",
       "      <th>新增确诊</th>\n",
       "      <th>最近更新时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>台湾</td>\n",
       "      <td>地区待确认</td>\n",
       "      <td>981141</td>\n",
       "      <td>1176</td>\n",
       "      <td>13742</td>\n",
       "      <td>85082</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>香港</td>\n",
       "      <td>地区待确认</td>\n",
       "      <td>331794</td>\n",
       "      <td>9365</td>\n",
       "      <td>61490</td>\n",
       "      <td>70</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>上海</td>\n",
       "      <td>黄浦</td>\n",
       "      <td>6553</td>\n",
       "      <td>0</td>\n",
       "      <td>5218</td>\n",
       "      <td>9</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>上海</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>4661</td>\n",
       "      <td>1</td>\n",
       "      <td>3516</td>\n",
       "      <td>4</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>上海</td>\n",
       "      <td>浦东</td>\n",
       "      <td>17036</td>\n",
       "      <td>1</td>\n",
       "      <td>15902</td>\n",
       "      <td>13</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>上海</td>\n",
       "      <td>虹口</td>\n",
       "      <td>3643</td>\n",
       "      <td>0</td>\n",
       "      <td>2632</td>\n",
       "      <td>7</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>上海</td>\n",
       "      <td>杨浦</td>\n",
       "      <td>2169</td>\n",
       "      <td>0</td>\n",
       "      <td>1194</td>\n",
       "      <td>18</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>上海</td>\n",
       "      <td>静安</td>\n",
       "      <td>3190</td>\n",
       "      <td>1</td>\n",
       "      <td>2416</td>\n",
       "      <td>13</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>上海</td>\n",
       "      <td>宝山</td>\n",
       "      <td>3028</td>\n",
       "      <td>1</td>\n",
       "      <td>2460</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>上海</td>\n",
       "      <td>长宁</td>\n",
       "      <td>2404</td>\n",
       "      <td>0</td>\n",
       "      <td>1876</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>上海</td>\n",
       "      <td>普陀</td>\n",
       "      <td>1780</td>\n",
       "      <td>0</td>\n",
       "      <td>1291</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>上海</td>\n",
       "      <td>嘉定</td>\n",
       "      <td>2615</td>\n",
       "      <td>2</td>\n",
       "      <td>2358</td>\n",
       "      <td>10</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>上海</td>\n",
       "      <td>松江</td>\n",
       "      <td>2966</td>\n",
       "      <td>0</td>\n",
       "      <td>2894</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>上海</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>4601</td>\n",
       "      <td>0</td>\n",
       "      <td>4591</td>\n",
       "      <td>1</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>北京</td>\n",
       "      <td>朝阳</td>\n",
       "      <td>489</td>\n",
       "      <td>0</td>\n",
       "      <td>21</td>\n",
       "      <td>8</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>北京</td>\n",
       "      <td>房山</td>\n",
       "      <td>271</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>9</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>北京</td>\n",
       "      <td>丰台</td>\n",
       "      <td>495</td>\n",
       "      <td>0</td>\n",
       "      <td>237</td>\n",
       "      <td>26</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>北京</td>\n",
       "      <td>海淀</td>\n",
       "      <td>224</td>\n",
       "      <td>0</td>\n",
       "      <td>26</td>\n",
       "      <td>6</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>北京</td>\n",
       "      <td>地区待确认</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>1288</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>浙江</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>594</td>\n",
       "      <td>0</td>\n",
       "      <td>374</td>\n",
       "      <td>1</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>吉林</td>\n",
       "      <td>白山</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>3</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>吉林</td>\n",
       "      <td>延边</td>\n",
       "      <td>181</td>\n",
       "      <td>0</td>\n",
       "      <td>171</td>\n",
       "      <td>3</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>河南</td>\n",
       "      <td>许昌</td>\n",
       "      <td>546</td>\n",
       "      <td>1</td>\n",
       "      <td>404</td>\n",
       "      <td>11</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>广东</td>\n",
       "      <td>广州</td>\n",
       "      <td>949</td>\n",
       "      <td>1</td>\n",
       "      <td>609</td>\n",
       "      <td>1</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>广东</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>3880</td>\n",
       "      <td>0</td>\n",
       "      <td>3861</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>四川</td>\n",
       "      <td>广安</td>\n",
       "      <td>163</td>\n",
       "      <td>0</td>\n",
       "      <td>31</td>\n",
       "      <td>33</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>四川</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>1328</td>\n",
       "      <td>0</td>\n",
       "      <td>1265</td>\n",
       "      <td>7</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>四川</td>\n",
       "      <td>资阳</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>福建</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>1090</td>\n",
       "      <td>0</td>\n",
       "      <td>980</td>\n",
       "      <td>7</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>天津</td>\n",
       "      <td>待确认</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>天津</td>\n",
       "      <td>北辰区</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>23</td>\n",
       "      <td>3</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>天津</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>616</td>\n",
       "      <td>0</td>\n",
       "      <td>615</td>\n",
       "      <td>1</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>云南</td>\n",
       "      <td>境外输入</td>\n",
       "      <td>1502</td>\n",
       "      <td>0</td>\n",
       "      <td>1483</td>\n",
       "      <td>2</td>\n",
       "      <td>2022-05-19 17:34:02</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     省份     城市    累计感染    死亡     治愈   新增确诊               最近更新时间\n",
       "0    台湾  地区待确认  981141  1176  13742  85082  2022-05-19 17:34:02\n",
       "1    香港  地区待确认  331794  9365  61490     70  2022-05-19 17:34:02\n",
       "2    上海     黄浦    6553     0   5218      9  2022-05-19 17:34:02\n",
       "3    上海     徐汇    4661     1   3516      4  2022-05-19 17:34:02\n",
       "4    上海     浦东   17036     1  15902     13  2022-05-19 17:34:02\n",
       "5    上海     虹口    3643     0   2632      7  2022-05-19 17:34:02\n",
       "6    上海     杨浦    2169     0   1194     18  2022-05-19 17:34:02\n",
       "7    上海     静安    3190     1   2416     13  2022-05-19 17:34:02\n",
       "9    上海     宝山    3028     1   2460      2  2022-05-19 17:34:02\n",
       "10   上海     长宁    2404     0   1876      2  2022-05-19 17:34:02\n",
       "11   上海     普陀    1780     0   1291      2  2022-05-19 17:34:02\n",
       "12   上海     嘉定    2615     2   2358     10  2022-05-19 17:34:02\n",
       "15   上海     松江    2966     0   2894      2  2022-05-19 17:34:02\n",
       "18   上海   境外输入    4601     0   4591      1  2022-05-19 17:34:02\n",
       "22   北京     朝阳     489     0     21      8  2022-05-19 17:34:02\n",
       "23   北京     房山     271     0     12      9  2022-05-19 17:34:02\n",
       "24   北京     丰台     495     0    237     26  2022-05-19 17:34:02\n",
       "25   北京     海淀     224     0     26      6  2022-05-19 17:34:02\n",
       "42   北京  地区待确认      60     0   1288      2  2022-05-19 17:34:02\n",
       "43   浙江   境外输入     594     0    374      1  2022-05-19 17:34:02\n",
       "59   吉林     白山      24     0     11      3  2022-05-19 17:34:02\n",
       "60   吉林     延边     181     0    171      3  2022-05-19 17:34:02\n",
       "70   河南     许昌     546     1    404     11  2022-05-19 17:34:02\n",
       "91   广东     广州     949     1    609      1  2022-05-19 17:34:02\n",
       "94   广东   境外输入    3880     0   3861      2  2022-05-19 17:34:02\n",
       "113  四川     广安     163     0     31     33  2022-05-19 17:34:02\n",
       "115  四川   境外输入    1328     0   1265      7  2022-05-19 17:34:02\n",
       "121  四川     资阳       5     0      4      1  2022-05-19 17:34:02\n",
       "136  福建   境外输入    1090     0    980      7  2022-05-19 17:34:02\n",
       "174  天津    待确认      24     0      0      4  2022-05-19 17:34:02\n",
       "175  天津    北辰区      29     0     23      3  2022-05-19 17:34:02\n",
       "176  天津   境外输入     616     0    615      1  2022-05-19 17:34:02\n",
       "194  云南   境外输入    1502     0   1483      2  2022-05-19 17:34:02"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np  #导入必要的库函数\n",
    "import pandas as pd\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import requests\n",
    "import json\n",
    "from pyecharts.globals import CurrentConfig, NotebookType\n",
    "CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB\n",
    "from pyecharts.charts import Map\n",
    "import pyecharts.options as opts\n",
    "import re\n",
    "\n",
    "#从文件中读取中国疫情的整体情况\n",
    "url1 = \"https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5\"\n",
    "resp=requests.get(url1)\n",
    "listdata=[]\n",
    "listdata=resp.json()\n",
    "today=''\n",
    "pattern=r\"}}\"\n",
    "m = re.search(pattern, listdata['data'][::-1])\n",
    "today=listdata['data'][:m.start()*-1]\n",
    "listdata1=json.loads(today+']} ] }] }')\n",
    "\n",
    "listtime=listdata1['lastUpdateTime']\n",
    "pd_china=pd.DataFrame()\n",
    "pd.set_option('display.max_columns', None)\n",
    "pd1=pd.DataFrame(listdata1['chinaTotal'],index=['chinaTotal'], columns=['confirm', 'heal','dead','suspect','nowConfirm','nowSevere','importedCase','noInfect'])\n",
    "pd_china = pd.concat([pd1, pd_china])\n",
    "\n",
    "pd1=pd.DataFrame(listdata1['chinaAdd'],index=['chinaAdd'], columns=['confirm', 'heal','dead','suspect','nowConfirm','nowSevere','importedCase','noInfect'])\n",
    "pd_china = pd.concat([pd1, pd_china])\n",
    "\n",
    "pd_china['lastUpdateTime']=listtime\n",
    "pd_china=pd_china.rename(columns={\"confirm\": \"累计确诊\", \"heal\": \"治愈\",\"dead\":\"累计死亡\",\"suspect\":\"疑是患者\",\"nowConfirm\":\"现有患者\",\"importedCase\":\"境外输入\",\"noInfect\":\"无症状感染者\",\"lastUpdateTime\":\"最近更新时间\",\"nowSevere\":\"重症患者\"})\n",
    "pd_china=pd_china.rename(index={\"chinaTotal\":\"中国累计\",\"chinaAdd\":\"中国新增\"})\n",
    "pd_china\n",
    "areaTree=listdata1['areaTree']  \n",
    "china_data=areaTree[0]['children']  #获得中国各省市数据\n",
    "china_data\n",
    "china_list = []\n",
    "for a in range(len(china_data)):   \n",
    "    province = china_data[a]['name']   #得到所有的省\n",
    "    province_list = china_data[a]['children']   #得到每个省的城市列表\n",
    "    for b in range(len(province_list)):\n",
    "        city = province_list[b]['name']  \n",
    "        total = province_list[b]['total']\n",
    "        today = province_list[b]['today']\n",
    "        china_dict = {}              #将每个城市的信息用字典存储\n",
    "        china_dict['province'] = province\n",
    "        china_dict['city'] = city\n",
    "        china_dict['total'] = total\n",
    "        china_dict['today'] = today\n",
    "        china_list.append(china_dict)\n",
    "china_data = pd.DataFrame(china_list)\n",
    "china_data['最近更新时间']=listtime\n",
    "# 定义数据处理函数\n",
    "def confirm(x):\n",
    "    confirm = eval(str(x))['confirm']\n",
    "    return confirm\n",
    "def dead(x):\n",
    "    dead = eval(str(x))['dead']\n",
    "    return dead\n",
    "def heal(x):\n",
    "    heal =  eval(str(x))['heal']\n",
    "    return heal\n",
    "# 函数映射\n",
    "china_data['confirm'] = china_data['total'].map(confirm)\n",
    "china_data['dead'] = china_data['total'].map(dead)\n",
    "china_data['heal'] = china_data['total'].map(heal)\n",
    "china_data['addconfirm'] = china_data['today'].map(confirm)\n",
    "china_data = china_data[[\"province\",\"city\",\"confirm\",\"dead\",\"heal\",\"addconfirm\"]]\n",
    "china_data=china_data.rename(columns={\"province\":\"省份\",\"city\":\"城市\",\"confirm\":\"累计感染\",\"dead\":\"死亡\",\"heal\":\"治愈\",\"addconfirm\":\"新增确诊\"})\n",
    "print('各省各地的疫情具体情况')\n",
    "china_data['最近更新时间']=listtime\n",
    "china_data\n",
    "china_data1=china_data[china_data['新增确诊']>=1]\n",
    "china_data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99bd4bb0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4678b1fe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d459c649",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
